package com.example.asus.listview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends AppCompatActivity {
    //定义，然后蒋定音的变量和布局的主键进行绑定
    private ListView nameListview;
    // 显示内容需要数据（数组，动态列表，xml文件，数据库）
    //数据（data）和列表（view）关联需要适配器（adapter）
    //适配器的作用是告诉界面怎么显示数据
    private String []nameArr={"张三","李四","晚五","赵思","六七",
            "李四","晚五","赵思","李四","晚五","赵思","李四","晚五","赵思","李四","晚五","赵思",};
    private ArrayAdapter<String>adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //然后将定义的变量和布局的主键进行绑定
        nameListview=findViewById(R.id.name_listview);
        adapter=new ArrayAdapter<String>(
                //listview 需要怎样布局，定义adapter，
                // 上下文，定义好的布局，数组
           MainActivity.this,
                android.R.layout.simple_list_item_1,
                nameArr
        );
        //绑定
nameListview.setAdapter(adapter);
    }
}
